﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Locations.aspx.cs" Inherits="NPMonitor.Web.Locations" MasterPageFile="~/Layout.master" %>
  <%@ Register Src="~/UserControls/PagerControl.ascx" TagName="PagerControl" TagPrefix="NPM" %>
  <%@ Register Src="~/UserControls/PoolInfo.ascx" TagName="PoolInfo" TagPrefix="NPM" %>
<%@ Import Namespace="NPMonitor" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
            <div class="Tab">
            <div class="TabTitle">
                <h2>
                    Machine Pool (<label id="lblPoolCount" runat="server" style="font-size: large;"><%=PoolCount%></label>items)</h2>
                <ul>
                    <li>Last Refresh：<span> <label id="lblLastRefresh" ><%=DateTime.Now.ToFormatString()%></label></span></li>
                    <li><asp:linkbutton runat="server" id="imgRefresh" class="refresh" onclick="imgRefresh_OnClick" CausesValidation = "false">
                        Refresh</asp:linkbutton></li>
                    <li>
                        <asp:LinkButton ID="lbtnCreatePool" class="create" runat="server" CausesValidation="false"
                            CommandName="Create" Text="Create Pool" OnClick="lbtnCreatePool_Click" />
                    </li>
                </ul>
                <div class="clear">
                </div>
            </div>
            <div class="TabContent">
                <table cellpadding="0" cellspacing="0" border="0" class="click">
                    <tr class="first">
                        <td width="25px">
                            ID
                        </td>
                        <td width="200px">
                            Pool Name
                        </td>
                        <td>
                            Comments
                        </td>
                        <td style="width:200px">
                            Operations
                        </td>
                    </tr>
                    <asp:Repeater ID="rpPoolList" runat="server" OnItemCommand="rpPoolList_OnItemCommand" OnItemDataBound="rpPoolList_OnItemDataBound" >
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <%#Eval("PoolId")%>
                                </td>
                                <td>
                                    <%#Eval("PoolName")%>
                                </td>
                                <td>
                                    <%#Eval("Comments")%>
                                </td>
                                <td>
                                    <asp:LinkButton ID="lbtnEditPool" runat="server" CommandArgument='<%#Eval("PoolId")%>' Text ="Edit" CausesValidation="false"  
                                        CommandName="EditPool" />
                                    <asp:LinkButton ID="lbtnDelete" runat="server" CommandArgument='<%#Eval("PoolId")%>' Text ="Delete"  CausesValidation="false" 
                                        CommandName="DeletePool" />
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
        </div>
        <NPM:PagerControl ID="ctPager" runat="server" />
    </div>
    <asp:PlaceHolder ID="phPoolInfo" Visible = "false" runat="server">
        <NPM:PoolInfo ID="ctPoolInfo" runat="server" />
    </asp:PlaceHolder>
   <script type="text/javascript">
       function DeletePoolValidate(PoolId) {
           var result = false;
           $.ajax({
               url: "/handler/UsersHandler.ashx?op=CheckPoolMachine",
               data: { PoolId: PoolId },
               async: false,
               cache: false,
               datatype: "json",
               success: function (data) {
                   result = (data == "true");
                   if (result) {
                       alert("Pool can not be delete, it contains machine.");
                       result = false;
                   }
                   else {
                       if (confirm('Are you sure to delete?')) {
                           result = true;
                       }
                   }
               }
           });
           return result;
       }
   </script>
</asp:Content>